<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>实例 - 二维码生成</title>
    <script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript" src="http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
</head>
<body>

<div id="qrcodeCanvas"></div>

<script>
    $(function () {

        var qrcode = $("#qrcodeCanvas").qrcode({
            render: "canvas", //设置渲染方式，有table和canvas，使用canvas方式渲染性能相对来说比较好
            text: utf16to8("哈哈哈哈"), //二维码的内容,可以直接填一个网址，扫描二维码后自动跳向该链接
            width: "256", //二维码宽度
            height: "256", //二维码高度
            background: "#ffffff", //二维码后景色
            foreground: "#000000", //二维码前景色
        });

    });

    function utf16to8(str) {
        var out, i, len, c;
        out = "";
        len = str.length;
        for (i = 0; i < len; i++) {
            c = str.charCodeAt(i);
            if ((c >= 0x0001) && (c <= 0x007F)) {
                out += str.charAt(i);
            } else if (c > 0x07FF) {
                out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
                out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
            } else {
                out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
                out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
            }
        }
        return out;
    }


</script>
</body>
</html>